﻿<UserControl x:Class="PurchaseSales.Manage.Views.AuthRoleView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity">
    <UserControl.Resources>
        <Style x:Key="CheckBoxFocusVisual">
            <Setter Property="Control.Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Border>
                            <Rectangle 
            Margin="15,0,0,0"
            StrokeThickness="1"
            Stroke="#60000000"
            StrokeDashArray="1 2"/>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style TargetType="CheckBox" x:Key="CheckBoxStyle">
            <Setter Property="SnapsToDevicePixels" Value="true"/>
            <Setter Property="OverridesDefaultStyle" Value="true"/>
            <Setter Property="FocusVisualStyle"    Value="{StaticResource CheckBoxFocusVisual}"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type CheckBox}">
                        <Border BorderBrush="{TemplateBinding BorderBrush}" 
            BorderThickness="{TemplateBinding BorderThickness}"    Background="{TemplateBinding Background}">
                            <Grid>
                                <ContentPresenter  Content="{TemplateBinding Content}" 
                ContentTemplate="{TemplateBinding ContentTemplate}"    Margin="{TemplateBinding Padding}" 
                HorizontalAlignment="{TemplateBinding   HorizontalContentAlignment}" 
                VerticalAlignment="{TemplateBinding    VerticalContentAlignment}" />
                                <Border x:Name="Checked" BorderThickness="3" BorderBrush="#FF41B1E1" Visibility="Collapsed">
                                    <Grid>
                                        <Path Width="33" Height="33" Stretch="Fill"  HorizontalAlignment="Right" VerticalAlignment="Top"  Fill="#FF41B1E1" Data="F1 M 294.469,237.943L 307.781,237.943L 307.781,250.276"/>
                                        <Path Width="16" Height="14" Fill="White"  Data="F1 M 263.89,239.418L 265.043,240.571L 267.402,238.212L 267.912,238.722L 265.553,241.081L 265.553,241.081L 265.043,241.591L 265.043,241.591L 264.533,241.081L 263.38,239.928L 263.89,239.418 Z " 
                                       HorizontalAlignment="Right" VerticalAlignment="Top" Stretch="Fill" Margin="0,1,1,0"/>
                                    </Grid>
                                </Border>
                            </Grid>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsChecked" Value="True">
                                <Setter TargetName="Checked" Property="Visibility" Value="Visible"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    <Grid VerticalAlignment="Stretch">
        <TabControl x:Name="tabControl">
            <!--<i:Interaction.Triggers>
                <i:EventTrigger EventName="SelectionChanged">
                    <i:InvokeCommandAction Command="{Binding LoadAuthRoleCommand}" CommandParameter="{Binding ElementName=tabControl, Path=SelectedIndex}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>-->
            <TabItem Header="用户设置">
                <!--<i:Interaction.Triggers>
                    <i:EventTrigger EventName="Loaded">
                        <i:InvokeCommandAction Command="{Binding LoadUserCommand}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>-->
                <DockPanel>
                    <UniformGrid   HorizontalAlignment="Right" Margin="10" DockPanel.Dock="Bottom">
                        <UniformGrid.Rows>1</UniformGrid.Rows>
                        <Button Content="添加" FontSize="14" MinWidth="80" Style="{DynamicResource SquareButtonStyle}" 
                                Margin="5"  FontFamily="Microsoft JhengHei, Segoe UI, PMingLiU" Command="{Binding AddUserCommand}"/>
                        <Button Content="编辑" FontSize="14" MinWidth="80" Style="{DynamicResource SquareButtonStyle}"
                                Margin="5"  FontFamily="Microsoft JhengHei, Segoe UI, PMingLiU" Command="{Binding EditUserCommand}"/>
                        <Button Content="删除" FontSize="14" Style="{DynamicResource SquareButtonStyle}" Margin="5" 
                                IsCancel="True" FontFamily="Microsoft JhengHei, Segoe UI, PMingLiU" Command="{Binding RemoveUserCommand}"/>
                    </UniformGrid>
                    <Grid>
                        <ListBox x:Name="UserList" ItemsSource="{Binding UsersCollection}" Background="Gray"
                                 ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                            <ListBox.ItemContainerStyle>
                                <Style TargetType="ListBoxItem">
                                    <Setter Property="SnapsToDevicePixels" Value="true"/>
                                    <Setter Property="OverridesDefaultStyle" Value="true"/>
                                    <Setter Property="VerticalContentAlignment" Value="Top"/>
                                    <Setter Property="HorizontalContentAlignment" Value="Left"/>
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="ListBoxItem">
                                                <Grid SnapsToDevicePixels="true" Margin="5" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
								HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}">
                                                    <ContentPresenter/>
                                                    <Border  x:Name="Checked" BorderThickness="3" BorderBrush="#FF41B1E1">
                                                        <Grid>
                                                            <Path Width="33" Height="33" Stretch="Fill"  HorizontalAlignment="Right" VerticalAlignment="Top"  Fill="#FF41B1E1" Data="F1 M 294.469,237.943L 307.781,237.943L 307.781,250.276"/>
                                                            <Path Width="16" Height="14" Fill="White"  Data="F1 M 263.89,239.418L 265.043,240.571L 267.402,238.212L 267.912,238.722L 265.553,241.081L 265.553,241.081L 265.043,241.591L 265.043,241.591L 264.533,241.081L 263.38,239.928L 263.89,239.418 Z " 
                                       HorizontalAlignment="Right" VerticalAlignment="Top" Stretch="Fill" Margin="0,1,1,0"/>
                                                        </Grid>
                                                    </Border>
                                                    <ToolTipService.ToolTip>
                                                        <StackPanel Orientation="Horizontal">

                                                            <TextBlock Text="姓名：" VerticalAlignment="Center"/>

                                                            <TextBlock Text="{Binding Name}" Grid.Column="1" VerticalAlignment="Center"/>
                                                        </StackPanel>
                                                    </ToolTipService.ToolTip>
                                                </Grid>
                                                <ControlTemplate.Triggers>
                                                    <Trigger Property="IsSelected" Value="true">
                                                        <Setter TargetName="Checked" Property="Visibility" Value="Visible"/>
                                                    </Trigger>
                                                    <Trigger Property="IsSelected" Value="false">
                                                        <Setter TargetName="Checked" Property="Visibility" Value="Hidden"/>
                                                    </Trigger>
                                                </ControlTemplate.Triggers>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </ListBox.ItemContainerStyle>
                            <ListBox.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <WrapPanel HorizontalAlignment="{TemplateBinding HorizontalAlignment}" 
					VerticalAlignment="{TemplateBinding VerticalAlignment}"/>
                                </ItemsPanelTemplate>
                            </ListBox.ItemsPanel>
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <Border Background="White" HorizontalAlignment="Left" VerticalAlignment="Top" Height="80" Width="100"
                            Padding="5">
                                        <TextBlock Text="{Binding Name}" FontSize="18" VerticalAlignment="Bottom"/>
                                    </Border>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="SelectionChanged">
                                    <i:InvokeCommandAction Command="{Binding SelectedUserCommand}" 
                                           CommandParameter="{Binding ElementName=UserList, Path=SelectedItem}"/>
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </ListBox>

                    </Grid>
                </DockPanel>
            </TabItem>
            <TabItem Header="角色设置">
               
                <DockPanel>
                    <UniformGrid   HorizontalAlignment="Right" Margin="10" DockPanel.Dock="Bottom">
                        <UniformGrid.Rows>1</UniformGrid.Rows>
                        <Button Content="添加" FontSize="14" MinWidth="80" Style="{DynamicResource SquareButtonStyle}" 
                                Margin="5"  FontFamily="Microsoft JhengHei, Segoe UI, PMingLiU" Command="{Binding AddCommand}"/>
                        <Button Content="编辑" FontSize="14" MinWidth="80" Style="{DynamicResource SquareButtonStyle}"
                                Margin="5"  FontFamily="Microsoft JhengHei, Segoe UI, PMingLiU" Command="{Binding EditCommand}"/>
                        <Button Content="删除" FontSize="14" Style="{DynamicResource SquareButtonStyle}" Margin="5" 
                                IsCancel="True" FontFamily="Microsoft JhengHei, Segoe UI, PMingLiU" Command="{Binding RemoveCommand}"/>
                    </UniformGrid>
                    <Grid>
                        <ListBox x:Name="RolesList" SelectionMode="Single"
                                 ItemsSource="{Binding AuthRolesCollection}" Background="Gray"
                                 ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                            <ListBox.ItemContainerStyle>
                                <Style TargetType="ListBoxItem">
                                    <Setter Property="SnapsToDevicePixels" Value="true"/>
                                    <Setter Property="OverridesDefaultStyle" Value="true"/>
                                    <Setter Property="VerticalContentAlignment" Value="Top"/>
                                    <Setter Property="HorizontalContentAlignment" Value="Left"/>
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="ListBoxItem">
                                                <Grid SnapsToDevicePixels="true" Margin="5" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
								HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}">
                                                    <ContentPresenter/>
                                                    <Border  x:Name="Checked" BorderThickness="3" BorderBrush="#FF41B1E1">
                                                        <Grid>
                                                            <Path Width="33" Height="33" Stretch="Fill"  HorizontalAlignment="Right" VerticalAlignment="Top"  Fill="#FF41B1E1" Data="F1 M 294.469,237.943L 307.781,237.943L 307.781,250.276"/>
                                                            <Path Width="16" Height="14" Fill="White"  Data="F1 M 263.89,239.418L 265.043,240.571L 267.402,238.212L 267.912,238.722L 265.553,241.081L 265.553,241.081L 265.043,241.591L 265.043,241.591L 264.533,241.081L 263.38,239.928L 263.89,239.418 Z " 
                                       HorizontalAlignment="Right" VerticalAlignment="Top" Stretch="Fill" Margin="0,1,1,0"/>
                                                        </Grid>
                                                    </Border>
                                                    <ToolTipService.ToolTip>
                                                        <StackPanel Orientation="Horizontal">

                                                            <TextBlock Text="角色名称：" VerticalAlignment="Center"/>

                                                            <TextBlock Text="{Binding RoleName}" Grid.Column="1" VerticalAlignment="Center"/>
                                                        </StackPanel>
                                                    </ToolTipService.ToolTip>
                                                </Grid>
                                                <ControlTemplate.Triggers>
                                                    <Trigger Property="IsSelected" Value="true">
                                                        <Setter TargetName="Checked" Property="Visibility" Value="Visible"/>
                                                    </Trigger>
                                                    <Trigger Property="IsSelected" Value="false">
                                                        <Setter TargetName="Checked" Property="Visibility" Value="Hidden"/>
                                                    </Trigger>
                                                </ControlTemplate.Triggers>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </ListBox.ItemContainerStyle>
                            <ListBox.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <WrapPanel HorizontalAlignment="{TemplateBinding HorizontalAlignment}" 
					VerticalAlignment="{TemplateBinding VerticalAlignment}"/>
                                </ItemsPanelTemplate>
                            </ListBox.ItemsPanel>
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <Border Background="White" HorizontalAlignment="Left" VerticalAlignment="Top" Height="80" Width="100"
                            Padding="5">
                                        <TextBlock Text="{Binding RoleName}" FontSize="18" VerticalAlignment="Bottom"/>
                                    </Border>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="SelectionChanged">
                                    <i:InvokeCommandAction Command="{Binding SetRoleCommand}" 
                                           CommandParameter="{Binding ElementName=RolesList, Path=SelectedItem}"/>
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </ListBox>

                    </Grid>
                </DockPanel>
            </TabItem>
            <TabItem Header="权限设置">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto"/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <TextBlock Text="角色列表" />
                    <ListBox x:Name="RoleList" Grid.Row="1"  ItemsSource="{Binding AuthRolesCollection}" Background="Gray"
                             ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                        <ListBox.ItemContainerStyle>
                            <Style TargetType="ListBoxItem">
                                <Setter Property="SnapsToDevicePixels" Value="true"/>
                                <Setter Property="OverridesDefaultStyle" Value="true"/>
                                <Setter Property="VerticalContentAlignment" Value="Top"/>
                                <Setter Property="HorizontalContentAlignment" Value="Left"/>
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="ListBoxItem">
                                            <Grid SnapsToDevicePixels="true" Margin="5" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
								HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}">
                                                <ContentPresenter/>
                                                <Border  x:Name="Checked" BorderThickness="3" BorderBrush="#FF41B1E1">
                                                    <Grid>
                                                        <Path Width="33" Height="33" Stretch="Fill"  HorizontalAlignment="Right" VerticalAlignment="Top"  Fill="#FF41B1E1" Data="F1 M 294.469,237.943L 307.781,237.943L 307.781,250.276"/>
                                                        <Path Width="16" Height="14" Fill="White"  Data="F1 M 263.89,239.418L 265.043,240.571L 267.402,238.212L 267.912,238.722L 265.553,241.081L 265.553,241.081L 265.043,241.591L 265.043,241.591L 264.533,241.081L 263.38,239.928L 263.89,239.418 Z " 
                                       HorizontalAlignment="Right" VerticalAlignment="Top" Stretch="Fill" Margin="0,1,1,0"/>
                                                    </Grid>
                                                </Border>
                                            </Grid>
                                            <ControlTemplate.Triggers>
                                                <Trigger Property="IsSelected" Value="true">
                                                    <Setter TargetName="Checked" Property="Visibility" Value="Visible"/>
                                                </Trigger>
                                                <Trigger Property="IsSelected" Value="false">
                                                    <Setter TargetName="Checked" Property="Visibility" Value="Hidden"/>
                                                </Trigger>
                                            </ControlTemplate.Triggers>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </ListBox.ItemContainerStyle>
                        <ListBox.ItemsPanel>
                            <ItemsPanelTemplate>
                                <WrapPanel HorizontalAlignment="{TemplateBinding HorizontalAlignment}" 
					VerticalAlignment="{TemplateBinding VerticalAlignment}"/>
                            </ItemsPanelTemplate>
                        </ListBox.ItemsPanel>
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Border Background="White" HorizontalAlignment="Left" VerticalAlignment="Top" Height="80" Width="100"
                            Padding="5">
                                    <TextBlock Text="{Binding RoleName}" FontSize="18" VerticalAlignment="Bottom"/>
                                </Border>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="SelectionChanged">
                                <i:InvokeCommandAction Command="{Binding SelectedRoleCommand}" 
                                           CommandParameter="{Binding ElementName=RoleList, Path=SelectedItem}"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </ListBox>

                    <TextBlock Text="当前角色权限列表" Grid.Column="1"/>
                    <ListBox x:Name="AuthList" Grid.Row="1" Grid.Column="1" SelectionMode="Multiple"  
                             ItemsSource="{Binding AuthModules}" Background="Gray"
                             ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                        <ListBox.ItemContainerStyle>
                            <Style TargetType="ListBoxItem">
                                <Setter Property="SnapsToDevicePixels" Value="true"/>
                                <Setter Property="OverridesDefaultStyle" Value="true"/>
                                <Setter Property="VerticalContentAlignment" Value="Top"/>
                                <Setter Property="HorizontalContentAlignment" Value="Left"/>
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="ListBoxItem">
                                            <ScrollViewer>
                                                <Grid SnapsToDevicePixels="true" Margin="5" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
								HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}">
                                                    <CheckBox IsChecked="{Binding IsSelected}" IsEnabled="{Binding DataContext.IsRoleSelected, 
                                                        RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" VerticalAlignment="Bottom" Style="{StaticResource CheckBoxStyle}">
                                                        <ContentPresenter/>
                                                        <i:Interaction.Triggers>
                                                            <i:EventTrigger EventName="Checked">
                                                                <i:InvokeCommandAction Command="{Binding DataContext.CheckedCommand,
                                                                RelativeSource={RelativeSource Mode=FindAncestor,
                                                                AncestorType=UserControl}}" CommandParameter="{Binding}" />
                                                            </i:EventTrigger>
                                                            <i:EventTrigger EventName="Unchecked">
                                                                <i:InvokeCommandAction Command="{Binding DataContext.UncheckedCommand,
                                                                RelativeSource={RelativeSource Mode=FindAncestor,
                                                                AncestorType=UserControl}}" CommandParameter="{Binding}"/>
                                                            </i:EventTrigger>
                                                        </i:Interaction.Triggers>
                                                    </CheckBox>
                                                </Grid>
                                            </ScrollViewer>

                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </ListBox.ItemContainerStyle>
                        <ListBox.ItemsPanel>
                            <ItemsPanelTemplate>
                                <WrapPanel HorizontalAlignment="{TemplateBinding HorizontalAlignment}" 
					VerticalAlignment="{TemplateBinding VerticalAlignment}"/>
                            </ItemsPanelTemplate>
                        </ListBox.ItemsPanel>
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Border Background="White"  Height="80" Width="100"
                            Padding="5">
                                    <TextBlock Text="{Binding ModuleName}" FontSize="18" VerticalAlignment="Bottom"/>
                                </Border>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </Grid>
            </TabItem>
        </TabControl>
    </Grid>
</UserControl>
